package JavaShengSai2;

import java.util.Scanner;

/**
 * 2. 回文日期
 * https://www.lanqiao.cn/problems/498/learning/?page=2&first_category_id=1&tags=2020,%E7%9C%81%E8%B5%9B&tag_relation=intersection&sort=pass_rate&asc=0
 */
public class Main2 {
    static int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    static boolean first = false; // 是否是第一个回文字符串
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int date = scan.nextInt();
        for(int i = date + 1;i <= 99999999;i++) {
            String s = i + "";
            boolean flag = true;
            // 先判断这个 日期 是否是回文字符串
            for(int k = 0,j = 7;k < 4;k++,j--) {
                if(s.charAt(k) != s.charAt(j)) {
                    flag = false;
                }
            }

            if(flag) {
                // 是回文的
                if(check_is(i) && !first) {
                    first = true;
                    System.out.println(i);
                }
                if(check_is(i) && check_ab(i)) {
                    System.out.println(i);
                    break;
                }
            }
        }
        scan.close();
    }

    public static boolean check_is(int x) {
        int day = x % 100;
        x /= 100;
        int month = x % 100;
        int year = x / 100;

        if(month > 12 || month < 1) {
            return false;
        }
        if(month == 2) {
            if(year % 100 != 0 && year % 4 == 0 && year % 400 == 0) {
                // 闰年
                if(day > 29) {
                    return false;
                }
            }
            if(day > 28) {
                return false;
            }
        }
        if(day == 0 || day > days[month]) {
            return false;
        }
        return true;
    }

    public static boolean check_ab(int x) {
        int a = x % 10;
        int b = x / 10 % 10;
        if(a == b) {
            return false;
        }
        String sa = a + "";
        String sb = b + "";
        String str = sa+sb+sa+sb+sb+sa+sb+sa;
        if(str.equals(x+"")) {
            return true;
        }
        return false;
    }
}
